package com.sgzn.sgpay.persistence.manager;

import com.sgzn.sgpay.enums.SgsResponseCode;
import com.sgzn.sgpay.exception.SgpayException;
import com.sgzn.sgpay.persistence.dao.TMerchantMapper;
import com.sgzn.sgpay.persistence.domain.TMerchant;
import com.sgzn.sgpay.persistence.domain.TMerchantExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by linliangfang 13580393408
 * DATETIME:2018/5/26 22:47
 * Description:
 */
@Component
public class MerchantDaoManager {

    @Autowired
    private TMerchantMapper tMerchantMapper;

    /**
     * 根据MchId返回Merchant信息
     * @param merchId
     * @return
     */
    public TMerchant getMerchantByMerchId(String merchId){
      //查询商户基础信息
      TMerchantExample tMerchantExample = new TMerchantExample();
      TMerchantExample.Criteria tMchCrit = tMerchantExample.createCriteria();
      tMchCrit.andMerchantIdEqualTo(merchId);
      List<TMerchant> tMerchantList = tMerchantMapper.selectByExample(tMerchantExample);
      if(CollectionUtils.isEmpty(tMerchantList)){
          throw new SgpayException(SgsResponseCode.C_MERCHANT_NOT_FOUND.getResponseCode(),SgsResponseCode.C_MERCHANT_NOT_FOUND.getResponseDesc());
      }
      return tMerchantList.get(0);
    }

}
